import { getVersion } from '@/api/home.js';
import { logout } from '@/api/my.js';
export default {
	data() {
		return {
			version: 0, //本地版本号
			outShow: false,
			userInfo: '',
			settingsList: [{
				name: '账号安全',
				url: '/pages/my/settings/safetyCenter',
				isShow: true
			}, {
				name: '关于我们',
				url: '/pages/my/vip/agreement?type=about_us&name=关于我们',
				isShow: true
			}, {
				name: '用户协议',
				url: '/pages/login/agreements?type=ios_user_agreement',
				isShow: true
			}, {
				name: '隐私协议',
				url: '/pages/login/agreements?type=ios_privacy_agreement',
				isShow: true
			}, {
				name: '会员协议',
				url: '/pages/my/vip/agreement?type=ios_vip_deal&name=会员协议',
				isShow: true
				},
				{
				name: '',
				url: '',
				isShow: true
			},],
		};
	},
	methods: {
		//菜单点击
		onClick(item) {
			if (item.url == '') {
				this.checkVersion()
			} else {
				this.$used.href(item.url);
			}
		},
		//检查版本号
		checkVersion() {
			//获取本地的版本号
			getVersion({}).then(({ code, data, msg }) => {
				if (code == 1) {
					let netVersionCode = parseInt(data.versioncode)
					if (this.version >= netVersionCode) {
						this.$used.msg('当前已是最新版本')
					} else {
						this.$used.msg('检测到最新版本,正在前往应用市场更新');
						setTimeout(() => {
							let platform = uni.getSystemInfoSync().platform
							if (platform == 'ios') {
								plus.runtime.openURL(
									"https://apps.apple.com/cn/app/%E5%B0%8F%E7%AB%B9%E8%B4%A2%E7%A8%8E/id1614986978"
								)
							} else if (platform == 'android') {
								plus.runtime.openURL(
									'http://a.app.qq.com/o/simple.jsp?pkgname=com.huizu.xiaozhucaishui');
							}
						}, 2000)
					}
				}
			})
		},
		//退出
		quit() {
			logout({}).then(res => {
				this.$used.msg('已退出')
				this.$used.outFun();
				uni.removeTabBarBadge({
					index: 2
				})
				// #ifdef APP-PLUS
				ZIM.getInstance().logout();
				// #endif
			})
		},
	},
	onLoad(e) {
		var that = this
		uni.getSystemInfo({
			success: function (res) {
				console.log(res)
				that.version = res.appVersionCode
				that.settingsList[that.settingsList.length - 1].name = '版本' + res.appVersion
			}
		});
	},
}